<!doctype html>
<html>
<head>
	<meta charset="UTF-8">
	<title></title>
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<link href="../css/mui.min.css" rel="stylesheet" />
	<link rel="stylesheet" href="../css/setting.css" />
</head>

<body class="white">
	<div class="mui-content">
	    <div class="forgettop"><img src="../icon/forget2.png" alt="" /></div>
	    <div class="forms">
		    	<div class="inputBox">
		    		<input type="password" name="" id="old" placeholder="旧密码" class="pwdIcon" />
		    	</div>
		    	<div class="inputBox">
		    		<input type="password" name="" id="news" placeholder="新密码" class="pwdIcon" />
		    	</div>
	    </div>
	    <div class="mui-content-padded" style="margin-top: 20px;">
	   		<button type="button" class="bexta-btn bexta-btn-red mui-btn mui-btn-block enter"  >确定</button>
	   </div>
	</div>
<script src="../js/mui.js"></script>
<script src="../js/bexta.js"></script>
<script type="text/javascript">
	mui.init()
	mui.plusReady(function () {
	    var codes = bexta.getWebview().codes;
	    if( bexta.getWebview().type == 'forget' ){
	    		document.querySelector('#old').placeholder = '新密码';
	    		document.querySelector('.enter').addEventListener('tap', function(){
	    			var old = document.querySelector('#old'),
		    			news = document.querySelector('#news');
		    		if( old.value != '' && old.value != news.value ){
		    			mui.toast("两次密码不一致");
		    			return;
		    		}
		    		bexta.ajax(api.forget_password, function(res, msg){
		    			mui.toast(msg);
		    			if( !res ){
		    				bexta.getWebview().opener().close('none');
		    				mui.later(function(){
		    					bexta.getWebview().close('none');
		    				},500, mui);
		    			}
		    		},{data:{
		    			code:bexta.getWebview().codes,
		    			mobile:bexta.getWebview().phone,
		    			newpass:old.value,
		    			ckpass:news.value
		    		}})
	    		});
	    }else{
		    	document.querySelector('.enter').addEventListener('tap', function(){
		    		var old = document.querySelector('#old'),
		    			news = document.querySelector('#news');
		    		if( old.value == '' || news.value == '' ){
		    			mui.toast("请填写完整");
		    			return ;
		    		}
		    		bexta.ajax(api.update_password, function(res,msg){
		    			mui.toast(msg);
		    			bexta.rmStorage(USER);
		    			if( !res ){
		    				mui.later(function(){
		    					bexta.goWebview(function(){
			    					mui.fire(plus.webview.getLaunchWebview(), 'toggleClick', {
			    						path:'index2'
			    					});
			    				});
		    				}, 300);
		    				
		    			}
		    		}, {data:{code:codes, oldpass:old.value, newpass:news.value, uid : bexta.getStorage(USER).uid}});
		    });
	    }
	});
</script>
</body>
</html>